package com.platform.admin.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;

/**
 * @Description: 模切设备型号
 * @author: yuanlai
 * @CreateTime: 2022/5/21 11:02
 */
@Getter
@AllArgsConstructor
public enum BeiDeviceTypeEnum {

    FA1("FA1", 5000, 999999999, BigDecimal.valueOf(1000), BigDecimal.valueOf(999999999), "||", "订单张数>5000 || 大版尺寸 >1000"),
    SA1("SA1", 2000, 5000, BigDecimal.valueOf(950), BigDecimal.valueOf(1000), "&&", "2000<=N<5000 && 950<=M<1000"),
    SA2("SA2", 2000, 5000, BigDecimal.valueOf(880), BigDecimal.valueOf(950), "&&", "2000<=N<5000 && 880<=M<950"),
    SA3("SA3", 2000, 5000, BigDecimal.valueOf(0), BigDecimal.valueOf(880), "&&", "2000<=N<5000 && M<880"),
    MO1("MO1", 0, 2000, BigDecimal.valueOf(950), BigDecimal.valueOf(1000), "&&", "0<=N<2000 && 950<=M<1000"),
    MO2("MO2", 0, 2000, BigDecimal.valueOf(880), BigDecimal.valueOf(950), "&&", "0<=N<2000 && 880<=M<950"),
    MO3("MO3", 0, 2000, BigDecimal.valueOf(0), BigDecimal.valueOf(880), "&&", "0<=N<2000 && 0<=M<880");

    private final String code;

    //订单张数左区间
    private final int countLeftRange;
    //订单张数右区间
    private final int countRightRange;
    //尺寸左区间
    private final BigDecimal sizeLeftRange;
    //尺寸右区间
    private final BigDecimal sizeRightRange;
    //尺寸和张数的关系
    private final String type;
    //描述
    private final String description;

    public static BeiDeviceTypeEnum getEnumByOrderCountAndSize(Integer count, BigDecimal size) {
        for (BeiDeviceTypeEnum beiDeviceTypeEnum : values()) {
            if (beiDeviceTypeEnum.type.equals("||")) {
                if ((count >= beiDeviceTypeEnum.countLeftRange && count < beiDeviceTypeEnum.countRightRange)
                        || (size.compareTo(beiDeviceTypeEnum.sizeLeftRange) >= 0 && size.compareTo(beiDeviceTypeEnum.sizeRightRange) < 0))
//                        ||( (NumberUtil.compare(size,beiDeviceTypeEnum.sizeLeftRange ) >= 0 && NumberUtil.compare(size,beiDeviceTypeEnum.sizeRightRange < 0) )))
                {
                    return beiDeviceTypeEnum;
                }
            }
            if (beiDeviceTypeEnum.type.equals("&&")) {
                if ((count >= beiDeviceTypeEnum.countLeftRange && count < beiDeviceTypeEnum.countRightRange)
                        && (size.compareTo(beiDeviceTypeEnum.sizeLeftRange) >= 0 && size.compareTo(beiDeviceTypeEnum.sizeRightRange) < 0)) {
                    return beiDeviceTypeEnum;
                }
            }
        }
        return null;
    }
}
